package com.example.service.impl;

import com.example.mapper.ShiftMapper;
import com.example.pojo.PageResult;
import com.example.pojo.Shift;
import com.example.service.ShiftService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShiftServiceImpl implements ShiftService {

    @Autowired
    private ShiftMapper shiftMapper;

    //分页查询班次
    public PageResult page(Integer page, Integer pageSize){
        //设置分页参数
        PageHelper.startPage(page, pageSize);
        //执行查询
        List<Shift> list = shiftMapper.findAll();
        Page<Shift> p = (Page<Shift>) list;
        //封装分页结果
        return new PageResult(p.getTotal(), p.getResult());
    }

    //删除班次
    public void deleteById(Integer ID){
        shiftMapper.deleteById(ID);
    }

    //添加班次
    public void save(Shift shift){
        shiftMapper.insert(shift);
    }

    //修改班次
    public void update(Shift shift){
        shiftMapper.update(shift);
    }

}
